<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../../../layui/css/layui.css" media="all">
    <script src="../../../js/jquery/1.x/jquery.js"></script>
    <script src="../../../layui/layui.js" charset="utf-8"></script>
    <script src="../../../js/config.js"></script>
    <script src="../../../js/function.js"></script>
    <script src="../../../js/public.js"></script>
    <link rel="stylesheet" href="../../../css/public.css">
    <link rel="stylesheet" href="../../../css/patient/qss.css">
    <style>
        .picBox {
            position: relative;
        }

        .btnUpload {
            width: 104px;
            height: 104px;
            position: relative;
            float: left;
            background: url(../../../img/shangchuanzhaopian.png) no-repeat;
            overflow: hidden;
            text-decoration: none;
            text-indent: 0;
        }

        .btnUpload input {
            position: absolute;
            width: 100px;
            height: 100px;
            right: 0;
            top: 0;
            opacity: 0;
        }

        .picList {
            float: left;
        }

        .picItem {
            width: 104px;
            height: 104px;
            text-align: center;
            display: inline-block;
            margin-right: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
            float: left;
            position: relative;
        }

        .picItem .pic {
            max-width: 100%;
            max-height: 100%;
            width: 104px;
            height: 104px;
            cursor: pointer;
        }

        .picItem .close1 {
            position: absolute;
            right: 2px;
            top: 2px;
            z-index: 1000;
            background: url("../../../img/cuowu.png") no-repeat;
            cursor: pointer;
            width: 20px;
            height: 20px;
        }

        .date {
            width: 80px!important;
            text-align: center
        }

        .layui-table .layui-input {
            border: 1px #d2d2d2 solid !important;
            height: 30px !important;
        }

        .qss-item-table .layui-table td {
            padding: 10px;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="tab-title">
            <ul class="tab-title-tab">
                <li>
                    <a href="../V1_1/patient_info.html">
                        <p>基本信息</p>
                        <p class="complete_basic">0%</p>
                    </a>
                </li>
                <li class="tab-curr">
                    <a>
                        <p>病历采集</p>
                        <p class="complete_qss">0%</p>
                    </a>
                </li>
                <li>
                    <a href="./qss7.html">
                        <p>检查信息</p>
                        <p style="display: none;">0%</p>
                    </a>
                </li>
                <div class="clear"></div>
            </ul>
        </div>
        <div class="qss-container">
            <div class="qss-box">
                <div class="qss-box-title">
                    <p>垂体疾病评估</p>
                </div>
                <form class="layui-form qss-form">
                    <div class="qss-item">
                        <div class="qss-item-title">
                            <p>1、术前评估情况：</p>
                        </div>
                        <div class="qss-form-item layui-form-item">
                            <div class="layui-form-label">a.术前评估科室</div>
                            <div class="qss-form-item-radio layui-form-item">
                                <input type="radio" title="内分泌科" name="128" class="cv-12801" data-qid="128" value="12801" lay-filter="radio">
                                <input type="radio" title="神经外科" name="128" class="cv-12802" data-qid="128" value="12802" lay-filter="radio">
                                <input type="radio" title="其他" name="128" class="cv-12803" data-qid="128" value="12803" lay-filter="radio">
                                <input type="text" class="layui-input radio-check-input cv-12803001" disabled="disabled" lay-verify="other_text" lay-verType="tips" autocomplete="off" name="12803001" data-qid="12803001">
                            </div>
                        </div>
                        <div class="qss-form-item layui-form-item switch-line">
                            <div class="layui-form-label">b.术前是否进行过垂体功能评估</div>
                            <div class="layui-input-inline qss-input-swipch">
                                <div class="switch3" data-qid="129" id="switch-129" title="是|否" option="0|1|2" value=""></div>
                            </div>
                        </div>

                    </div>
                    <div class="qss-item">
                        <div class="qss-item-title">
                            <p>2、术前影像学评估：</p>
                        </div>
                        <div class="qss-form-item layui-form-item">
                            <div class="layui-form-label">a.垂体MRI</div>
                            <div class="qss-form-item-radio layui-form-item">
                                <input type="radio" title="无异常" name="131" class="cv-13101" data-qid="131" value="13101" lay-filter="radio">
                                <input type="radio" title="微腺瘤（<10mm）" name="131" class="cv-13102" data-qid="131" value="13102" lay-filter="radio">
                                <input type="radio" title="大腺瘤（&ge;10mm）" name="131" class="cv-13103" data-qid="131" value="13103" lay-filter="radio">
                                <input type="radio" title="巨腺瘤（&ge;40mm）" name="131" class="cv-13104" data-qid="131" value="13104" lay-filter="radio">
                                <input type="radio" title="空蝶鞍" name="131" class="cv-13105" value="13105" data-qid="131" lay-filter="radio">
                                <input type="radio" title="垂体柄阻断综合征" name="131" class="cv-13106" data-qid="131" value="13106" lay-filter="radio">
                                <input type="radio" title="垂体柄增粗" name="131" class="cv-13107" data-qid="131" value="13107" lay-filter="radio">
                                <input type="radio" title="未评估" name="131" class="cv-13109" data-qid="131" value="13109" lay-filter="radio">
                                <input type="radio" title="其他" name="131" class="cv-13108" data-qid="131" value="13108" lay-filter="radio">
                                <input type="text" class="layui-input radio-check-input cv-13108001" autocomplete="off" lay-verify="other_text" lay-verType="tips" disabled="disabled" data-qid="13108001"><br/>
                            </div>
                            <div class="layui-form-label" style="display: block">垂体占位直径<input type="text" name="131001" lay-filter="input1" autocomplete="off" class="cv-131">cm</div>
                        </div>
                        <div class="qss-form-item layui-form-item">
                            <div class="layui-form-label">b.肾上腺CT</div>
                            <div class="qss-form-item-radio layui-form-item">
                                <input type="radio" title="无异常" name="132" class="cv-13201" data-qid="132" value="13201" lay-filter="radio">
                                <input type="radio" title="增生" name="132" class="cv-13202" data-qid="132" value="13202" lay-filter="radio">
                                <input type="radio" title="占位" name="132" class="cv-13203" data-qid="132" value="13203" lay-filter="radio">
                                <input type="radio" title="未评估" name="132" class="cv-13204" data-qid="132" value="13204" lay-filter="radio">

                            </div>
                            <div class="layui-upload">
                                <!-- <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">

                                    <div class="layui-upload-list" id="demo2"></div>
                                </blockquote> -->
                                <div class="qss-form-item layui-form-item picBox" style="display: none;">
                                    <div class="qss-item-title">
                                        <p style="color:#4777E7;">影像学报告上传：</p>
                                    </div>
                                    <div class="qss-form-item layui-form-item picBox">
                                        <div class="picList">

                                        </div>
                                        <div class="btnUpload" id="btnUpload">
                                            <input type="file" id="fileUpload" accept="image/*" />
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="qss-form-item layui-form-item ct-132" style="display:none;">
                            <div class="layui-form-label">位置</div>
                            <div class="qss-form-item-radio layui-form-item">
                                <input type="radio" title="左侧" name="133" class="cv-13301" data-qid="133" value="13301" lay-filter="radio">
                                <input type="radio" title="右侧" name="133" class="cv-13302" data-qid="133" value="13302" lay-filter="radio">
                                <input type="radio" title="双侧" name="133" class="cv-13303" data-qid="133" value="13303" lay-filter="radio">
                            </div>
                            <div class="layui-form-label layui-form-item" style="margin-bottom:5px;display: none">左侧肾上腺占位直径<input type="text" name="133001" lay-filter="input1" autocomplete="off" class="cv-133001" maxlength="6">cm</div>
                            <div class="layui-form-label layui-form-item" style="margin-bottom:5px;display: none">右侧肾上腺占位直径<input type="text" name="133002" lay-filter="input1" autocomplete="off" class="cv-133002" maxlength="6">cm</div>
                        </div>
                    </div>
                    <div class="qss-item">
                        <div class="qss-item-title">
                            <p>3、术前视野评估：</p>
                        </div>
                        <div class="qss-form-item layui-form-item">
                            <div class="layui-form-label">视野评估状况</div>
                            <div class="qss-form-item-radio layui-form-item">
                                <input type="radio" title="存在视野缺陷" name="134" class="cv-134001" data-qid="134" value="134001" lay-filter="radio">
                                <input type="radio" title="否" name="134" class="cv-134002" data-qid="134" value="134002" lay-filter="radio">
                                <input type="radio" title="未评估" name="134" class="cv-134003" data-qid="134" value="134003" lay-filter="radio">
                                <input type="radio" title="其他" name="134" class="cv-134004" data-qid="134" value="134004" lay-filter="radio">
                                <input type="text" class="layui-input radio-check-input cv-134004001" autocomplete="off" lay-verify="other_text" lay-verType="tips" disabled="disabled" data-qid="134004001">
                            </div>
                        </div>
                    </div>
                    <div class="qss-item">
                        <div class="qss-item-title">
                            <p>4、目前垂体功能状态：</p>
                        </div>
                        <div class="qss-form-item layui-form-item">
                            <div class="layui-form-label">垂体功能状态评估情况</div>
                            <div class="qss-form-item-checkbox layui-form-item">
                                <input type="checkbox" lay-skin="primary" title="肾上腺皮质功能减退" name="135" class="cv-135001" value="135001" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="甲状腺功能减退" name="135" class="cv-135002" value="135002" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="性腺功能减退" name="135" class="cv-135003" value="135003" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="尿崩症" name="135" class="cv-135004" value="135004" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="垂体功能正常范围" name="135" class="cv-135005" value="135005" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="未评估" name="135" class="cv-135006" value="135006" lay-filter="check1">
                                <input type="checkbox" lay-skin="primary" title="垂体功能亢进" name="135" class="cv-135007" value="135007" lay-filter="check1">

                            </div>
                        </div>
                    </div>
                    <div class="qss-item-btn">
                        <div class="qss-item-btn">
                            <a href="javascript:;">
                                <button type="button" lay-submit="" lay-filter="submit-btn" data-type="1">提交并跳转下一页</button>
                            </a>
                            <a href="javascript:;">
                                <button type="button" lay-submit="" lay-filter="submit-btn" data-type="0">保存并留在本页</button>
                            </a>
                            <a href="qss3.html">
                                <button type="button">放弃编辑并跳转下一页</button>
                            </a>
                        </div>
                    </div>
                </form>
                <div class="fixed-nav">

                    <ul>
                        <li><a href="./qss1.html"><span>个人疾病史</span><span class="complete_qss1"></span><div class="clear"></div></a></li>
                        <li class="fixed-nav-curr"><a><span>垂体疾病评估</span><span class="complete_qss2"></span><div class="clear"></div></a></li>
                        <li><a href="./qss3.html"><span>垂体疾病用药</span><span class="complete_qss3"></span><div class="clear"></div></a></li>
                        <li><a href="./qss4.html"><span>合并症评估</span><span class="complete_qss4"></span><div class="clear"></div></a></li>
                        <li><a href="./qss5.html"><span>合并症用药</span><span class="complete_qss5"></span><div class="clear"></div></a></li>
                        <li><a href="./qss6.html"><span>垂体疾病治疗</span><span class="complete_qss6"></span><div class="clear"></div></a></li>
                    </ul>

                    <button type="button" lay-submit="" lay-filter="submit-btn" data-type="1">提交</button>
                </div>
            </div>
        </div>

    </div>
</body>
<script>
    var question = {
        128: [0, '', 's1'], //术前评估科室
        129: [12902, '否', 's1'], //术前是否进行过垂体功能评估
        131: [0, '', 's1'], //垂体MRI
        132: [0, '', 's1'], //肾上腺CT
        133: [0, '', 's1'], //肾上腺CT位置
        134: [0, '', 's1'], //视野评估情况
        'check_list': {}, //复选的内容
        'input_list': {}, //输入框内容
        156: [], // 上传图片
    };

    function initForm(patient_id, callback) {
        ajax_get(configUrl.qssInfo, {
            user_id: patient_id,
            visit_level: 1,
            template_id: 12
        }, (res) => {
            console.log(res.data.question_data);
            var arr1 = [128, 131, 132, 133, 134] //单选
            $.each(res.data.question_data, function(index, item) {
                var qid = parseInt(item.question_id);
                //开关
                if (qid == 129) {
                    if (item.answer.length > 0) {
                        if (item.answer[0].answer_id == (qid + '01')) {
                            $("input[name='q" + qid + "']").attr('checked', true);
                            $("#switch-" + qid).attr('value', 1);
                        } else {
                            $("#switch-" + qid).attr('value', 2);
                            $("input[name='q" + qid + "']").attr('checked', false);
                        }
                        question[qid][0] = item.answer[0].answer_id;
                        question[qid][1] = item.answer[0].answer_value;
                    } else {
                        question[qid][0] = 0;
                    }

                }
                //复选框
                if (qid == 135) {
                    $.each(item.answer, function(index, item2) {
                        $(".cv-" + item2.answer_id).attr('checked', true);
                        question['check_list'][item2.answer_id] = item2.answer_value;
                    })
                }
                //输入框
                if (qid == 128) {
                    $.each(item.answer, function(index, item2) {
                        if (item.answer[0].answer_id == 12803001) {
                            $('.cv-12803001').val(item.answer[0].answer_value);
                        }
                    })
                }
                if (qid == 131) {
                    $.each(item.answer, function(index, item2) {
                        if (item.answer[0].answer_id == 13102001 || item.answer[0].answer_id == 13103001 || item.answer[0].answer_id == 13104001) {
                            $('.cv-131').val(item.answer[0].answer_value);
                        }
                        if (item.answer[0].answer_id == 13108001) {
                            $('.cv-13108001').val(item.answer[0].answer_value);
                        }
                    })
                }
                if (qid == 133) {
                    $.each(item.answer, function(index, item2) {
                        if (item.answer[0].answer_id == 13301001) {
                            $('.cv-133001').val(item.answer[0].answer_value);
                        }
                        if (item.answer[0].answer_id == 13302001) {
                            $('.cv-133002').val(item.answer[0].answer_value);
                        }
                        if (item.answer[0].answer_id == 13303001) {
                            $('.cv-133001').val(item.answer[0].answer_value);
                        }
                        if (item.answer[0].answer_id == 13303002) {
                            $('.cv-133002').val(item.answer[0].answer_value);
                        }
                    })
                }
                if (qid == 134) {
                    $.each(item.answer, function(index, item2) {
                        if (item.answer[0].answer_id == 134004001) {
                            $('.cv-134004001').val(item.answer[0].answer_value);
                        }
                    })
                }
                //单选
                if (arr1.includes(qid)) {
                    if (item.answer.length > 0 && item.answer[0].answer_id.length < 8) {
                        $(".cv-" + item.answer[0].answer_id).attr('checked', true);
                        question[qid][0] = item.answer[0].answer_id;
                        question[qid][1] = item.answer[0].answer_value;
                        if (qid == 128) {
                            if (item.answer[0].answer_id == 12803) {
                                $('.cv-12803001').prop('disabled', false);
                            }
                        }
                        if (qid == 131) {
                            if (item.answer[0].answer_id == 13102 || item.answer[0].answer_id == 13103 || item.answer[0].answer_id == 13104) {
                                $('.cv-131').parent().show();
                                $('.cv-131').attr('data-qid', item.answer[0].answer_id + '001')
                            } else {
                                $('.cv-131').parent().hide();
                                $('.cv-131').attr('data-qid', '')
                            }
                            if (item.answer[0].answer_id == 13108) {
                                $('.cv-13108001').prop('disabled', false);
                            }
                        }
                        if (qid == 132) {
                            if (item.answer[0].answer_id == 13202 || item.answer[0].answer_id == 13203) {
                                $('.ct-132').show();
                            }
                        }
                        if (qid == 134) {
                            if (item.answer[0].answer_id == 134004) {
                                $('.cv-134004001').prop('disabled', false);
                            }
                        }
                        if (item.answer[0].answer_id == 13301) {
                            $(".cv-133001").parent().show();
                            $(".cv-133002").parent().hide();
                            $(".cv-133001").attr('data-qid', item.answer[0].answer_id + '001')
                            $(".cv-133002").attr('data-qid', '')
                        }
                        if (item.answer[0].answer_id == 13302) {
                            $(".cv-133001").parent().hide();
                            $(".cv-133002").parent().show();
                            $(".cv-133002").attr('data-qid', item.answer[0].answer_id + '001');
                            $(".cv-133001").attr('data-qid', '')
                        }
                        if (item.answer[0].answer_id == 13303) {
                            $(".cv-133001").parent().show();
                            $(".cv-133002").parent().show();
                            $(".cv-133001").attr('data-qid', item.answer[0].answer_id + '001');
                            $(".cv-133002").attr('data-qid', item.answer[0].answer_id + '002');
                        }
                    }

                }
            })
            callback();
        })
    }
    $(document).ready(function() {
        var height = $(window).height() - 2;
        //$('.container').height(height);
        var patient_id = getLocalStorage('patient_id');

        //完整度
        getCompletion();

        function addPicItem(src, id) {
            var randId = Math.floor(Math.random() * 1000);
            var str = '<div class="picItem" id="pic-' + randId + '" data-id="' + id + '">\n' +
                '<img class="pic" src="' + src + '" />\n' +
                '<div class="close1"></div> </div>';
            $(".picList").append(str);
        }
        //删除图片
        $(".picList").on('click', ".close1", function() {
            var picId = $(this).parents('.picItem').attr('data-id');
            console.log('picId=', picId);
            for (var i = 0; i < question[156].length; i++) {
                if (question[156][i] == picId) {
                    question[156].splice(i, 1);
                }
            }

            $(this).parents('.picItem').remove();
            console.log(question[156]);
        });
        //预览图片
        $('.picList').on('click', '.pic', function() {
            that = $(this);
            let img = new Image();
            img.src = $(this).attr('src');

            console.log(img.width + ';' + img.height);
            width = img.width;
            height = img.height;
            //if(width>600px;)
            layer.open({
                type: 1,
                title: false,
                closeBtn: 0,
                area: ['auto'],
                skin: 'layui-layer-nobg', //没有背景色
                shadeClose: true,
                content: '<div style="width:' + width + ';height:' + height + ';max-width:600px;max-height:500px;"><img src="' + that.attr('src') + '" width="100%" height="100%" /></div>'
            });
        });
        //上传图片
        $("#fileUpload").change(function() {
            console.log($("#fileUpload")[0].files[0]);
            var fileType = $("#fileUpload")[0].files[0].type;
            if (fileType != 'image/jpeg' && fileType != 'image/jpg' && fileType != 'image/png') {
                layer.msg('请选择图片文件');
                return false;
            }

            var fileSize = $("#fileUpload")[0].files[0].size;
            if (fileSize > 10485760) {
                layer.msg('上传的图片不能超过10M');
                return false;
            }

            addPicItem(URL.createObjectURL($(this)[0].files[0]), 0);
            //var files = $(this).prop('files');
            //console.log(files);
            let formData = new FormData;
            //formData.append('fileData',$("#fileUpload").prop('files')[0]);
            formData.append('filedata', $("#fileUpload")[0].files[0]);
            formData.append('user_id', patient_id);
            formData.append('doc_id', getLocalStorage('doc_id'));
            formData.append('visit_level', 1);
            var token = getLocalStorage('token');
            var headers = {};
            if (token) {
                headers.Authorization = 'Bearer ' + token;
            }
            console.log(formData, 'data')
            $.ajax({
                url: configUrl.host + '/api/v1/pituitary/upload',
                type: 'POST',
                data: formData,
                processData: false,
                cache: false,
                contentType: false,
                headers: headers,
                success: function(res) {
                    console.log(res);
                    if (res.status == 0) {
                        var randId = Math.floor(Math.random() * 1000);
                        question[156].push(res.data.id);
                        $("#pic-" + randId).attr('data-id', res.data.id);
                        console.log(question[156]);
                    }
                },
                error: function() {
                    alert('上传失败');
                }
            })
        });


        layui.config({
            base: '../../../layui/layui_exts/'
        }).extend({
            switch3: 'switch3/switch3'
        }).use(['element', 'form', 'layer', 'laydate', 'laypage', 'switch3'], function() {
            var element = layui.element;
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;
            var laypage = layui.laypage,
                switch3 = layui.switch3;


            //时间最大时
            var now = new Date();
            var year = parseInt(now.getFullYear());
            var month = parseInt(now.getMonth() + 1);
            var day = now.getDate();
            var max_date = year + '-' + month + '-' + day;
            initForm(patient_id, function() {
                switch3.render({
                    elem: '.switch3',
                    done: function(val, item) {
                        qid = item.parent().parent().attr('data-qid');
                        console.log('s-', val + '; qid=' + qid);
                        if (val == 0) {
                            question[qid][0] = 0;
                            question[qid][1] = '';
                        } else if (val == 1) {
                            question[qid][0] = qid + '01';
                            question[qid][1] = item.html();
                        } else if (val == 2) {
                            question[qid][0] = qid + '02';
                            question[qid][1] = item.html();
                        }
                    }
                });
                form.render();
            });

            //出生日期
            laydate.render({
                elem: '#bday',
                'max': max_date,
            });


            //开关切换
            form.on('switch(switch1)', function(data) {
                var qid = $(this).attr('data-qid')
                if (this.checked) {
                    question[qid][0] = qid + '01';
                    question[qid][1] = '是';
                } else {
                    question[qid][0] = qid + '02';
                    question[qid][1] = '否';
                }
            });
            //单选框切换
            form.on('radio(radio)', function(data) {
                var qid = $(this).attr('data-qid');
                if (data.elem.checked) {
                    question[qid][0] = data.value;
                    question[qid][1] = $(this).attr('title');
                    if (qid == 131) {
                        if (data.value == 13102 || data.value == 13103 || data.value == 13104) {
                            $('.cv-131').parent().show()
                            $('.cv-131').attr('data-qid', data.value + '001')
                        } else {
                            $('.cv-131').parent().hide()
                            $('.cv-131').val('');
                            $('.cv-131').attr('data-qid', '')
                        }
                        if (data.value == 13108) {
                            $('.cv-13108001').prop('disabled', false);
                        } else {
                            $('.cv-13108001').prop('disabled', true);
                            $('.cv-13108001').val('');
                        }
                    }
                    if (qid == 132) {
                        if (data.value == 13202 || data.value == 13203) {
                            $('.ct-132').show()
                        } else {
                            $('.ct-132').hide()
                        }
                    }
                    if (qid == 128) {
                        if (data.value == 12803) {
                            $('.cv-12803001').prop('disabled', false);
                        } else {
                            $('.cv-12803001').prop('disabled', true);
                            $('.cv-12803001').val('');
                        }
                    }
                    if (qid == 134) {
                        if (data.value == 134004) {
                            $('.cv-134004001').prop('disabled', false);
                        } else {
                            $('.cv-134004001').prop('disabled', true);
                            $('.cv-134004001').val('');
                        }
                    }
                    if (data.value == 13301) {
                        $(".cv-133001").parent().show();
                        $(".cv-133002").parent().hide();
                        $(".cv-133001").attr('data-qid', data.value + '001')
                        $(".cv-133002").attr('data-qid', '')
                    }
                    if (data.value == 13302) {
                        $(".cv-133001").parent().hide();
                        $(".cv-133002").parent().show();
                        $(".cv-133002").attr('data-qid', data.value + '001');
                        $(".cv-133001").attr('data-qid', '')
                    }
                    if (data.value == 13303) {
                        $(".cv-133001").parent().show();
                        $(".cv-133002").parent().show();
                        $(".cv-133001").attr('data-qid', data.value + '001');
                        $(".cv-133002").attr('data-qid', data.value + '002');
                    }
                } else {
                    question[qid][0] = 0;
                    question[qid][1] = '';
                    if (qid == 131) {
                        if (data.value == 13102 || data.value == 13103 || data.value == 13104) {
                            $('.cv-131').parent().hide()
                            $('.cv-131').val('');
                            $('.cv-131').attr('data-qid', '')
                        }
                        if (data.value == 13108) {
                            $('.cv-13108001').prop('disabled', true);
                            $('.cv-13108001').val('');
                        }
                    }
                    if (qid == 132) {
                        if (data.value == 13202 || data.value == 13203) {
                            $('.ct-132').hide()
                        }
                    }
                    if (qid == 128) {
                        console.log(data.value)
                        if (data.value == 12803) {
                            $('.cv-12803001').prop('disabled', true);
                            $('.cv-12803001').val('');
                        }
                    }
                    if (qid == 134) {
                        if (data.value == 134004) {
                            $('.cv-134004001').prop('disabled', true);
                            $('.cv-134004001').val('');
                        }
                    }
                    if (qid == 133) {
                        $(".cv-133001").parent().hide();
                        $(".cv-133002").parent().hide();
                        $(".cv-133001").attr('data-qid', '')
                        $(".cv-133002").attr('data-qid', '')
                        $(".cv-133001").val('');
                        $(".cv-133002").val('');
                    }
                }


            });
            //复选框选中与否切换
            form.on('checkbox(check1)', function(data) {
                var val = $(this).attr('title');
                var qid2 = data.value;
                if (this.checked) {
                    question['check_list'][qid2] = val;
                } else {
                    delete question.check_list[qid2];
                }
            });

            // v1.1 信息校验
            form.verify({
                other_text: function(value) {
                    if (value.length > 20) {
                        return '输入内容不能超过20个字';
                    }
                },
            });

            //提交
            form.on('submit(submit-btn)', function() {
                var jumpType = $(this).attr('data-type')
                delete question.input_list;
                question.input_list = {};
                if ($(".cv-131").attr('data-qid')) {
                    console.log($(".cv-131").val());
                    question['input_list'][$(".cv-131").attr('data-qid')] = $(".cv-131").val();
                }
                if ($(".cv-133001").attr('data-qid')) {
                    question['input_list'][$(".cv-133001").attr('data-qid')] = $(".cv-133001").val();
                }
                if ($(".cv-133002").attr('data-qid')) {
                    question['input_list'][$(".cv-133002").attr('data-qid')] = $(".cv-133002").val();
                }
                question['input_list'][$(".cv-12803001").attr('data-qid')] = $(".cv-12803001").val();
                question['input_list'][$(".cv-134004001").attr('data-qid')] = $(".cv-134004001").val();
                question['input_list'][$(".cv-13108001").attr('data-qid')] = $(".cv-13108001").val();
                var chapterId = 1201;
                var visitLevel = 1;
                var params = {
                    'hosp_id': getLocalStorage('hosp_id'),
                    'dept_id': getLocalStorage('dept_id'),
                    'user_id': getLocalStorage('patient_id'),
                    'doc_id': getLocalStorage('doc_id'),
                    'visit_level': 1,
                    'template_id': 12,
                    'terminal_flg': 0,
                    'data': [{
                        'visit_level': 1,
                        'user_id': getLocalStorage('patient_id'),
                        'doc_id': getLocalStorage('doc_id'),
                        "terminal_flg": "0",
                        'template_id': 12,
                        "datasource": "2",
                        'answer': []
                    }]
                };
                var answer = [];
                //只有切换
                $.each(question, function(qid, item) {
                    if (item[2] == 's1') {
                        if (question[qid][0] != 0) {
                            answer.unshift({
                                'chapter_id': chapterId,
                                'question_id': qid,
                                'subquestion_id': qid,
                                'answer_id': question[qid][0],
                                'answer_name': question[qid][1],
                                'visit_level': visitLevel
                            });
                        }
                    }
                });
                //多选
                $.each(question.check_list, function(qid2, item) { //qid2:134003
                    var qid = parseInt(parseInt(qid2) / 1000);
                    answer.push({
                        'chapter_id': chapterId,
                        'question_id': qid,
                        'subquestion_id': qid,
                        'answer_id': qid2,
                        'answer_name': item,
                        'visit_level': visitLevel
                    })

                });
                $.each(question.input_list, function(qid3, item) {
                    console.log(qid3);
                    if (qid3.length == 9) {
                        var qid = parseInt(parseInt(qid3) / 1000000);
                    } else {
                        var qid = parseInt(parseInt(qid3) / 100000);
                    }
                    answer.push({
                        'chapter_id': chapterId,
                        'question_id': qid,
                        'subquestion_id': qid3,
                        'answer_id': qid3,
                        'answer_name': item,
                        'visit_level': visitLevel
                    })
                })
                params.data[0].answer = answer;
                ajax_post(configUrl.qssInfo, params, function(res) {
                    if (res.status == '0') {
                        layer.msg('操作成功', {
                            icon: 6,
                            time: 1000
                        }, function() {
                            if (jumpType == 0) {
                                //不跳转
                                window.location.reload();
                            } else {
                                //跳转
                                window.location.href = 'qss3.html';
                            }

                        });
                    } else {
                        layer.msg(res.msg, {
                            icon: 5
                        });
                    }
                });
                return false;
                alert(3);
            })





            /*$('.sex-btn').click(function () {
                if ($(this).hasClass('sex-btn-checked')) {
                    console.log('true')
                } else {
                    $(this).addClass('sex-btn-checked');
                    $(this).siblings().removeClass('sex-btn-checked');
                    var value = $(this).attr('data-val');
                    $('input[name=has]').val(value);
                    if (value == 1) {
                        $('.has-pituitary').show();
                        $('.no-has-pituitary').hide();
                    } else {
                        $('.has-pituitary').hide();
                        $('.no-has-pituitary').show();
                    }
                }
            });
            form.on('submit(submit-btn)', function (data) {
                $('.add-container').hide();
                $('.result-box').show();
                console.log(data.field);
                //倒计时2s进度条变成100%
                var n = 0, timer = setInterval(function () {
                    n = n + 50;
                    if (n > 100) {
                        n = 100;
                        clearInterval(timer);
                        layer.msg('生成成功', {icon: 1, time: 1000}, function () {
                            console.log('tiaozhuan')
                        });
                    }
                    element.progress('result-progress', n + '%');
                    console.log(n);
                }, 300 + Math.random() * 1000);
            });
*/
        })
    })
</script>

</html>
